package com.sunlands.deskmate.service.task;

import com.sunlands.deskmate.repository.DicRepository;
import com.sunlands.deskmate.service.DicServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class TaskDicServiceImpl {

    @Autowired
    private DicRepository dicRepository;

    @Scheduled(cron = "0 0/1 * * * ?")
    public void refreshAll() {
        log.debug("刷新全部字典信息");
        dicRepository.findAll().forEach(dic -> DicServiceImpl.dicCache.put(dic.getCode(), dic));
    }

}